//index.js
const numberBoard = require('../../lib/numberBoard.js')
const user = require('../../lib/user.js')
//获取应用实例
const app = getApp()

Page({
  data: {
    board: {},
    user: {},
    inputValue: '',// 用户输入的数据
    beat: false
  },
  onLoad: function () {
    this._bindData()
  },

  _bindData: function() {
    numberBoard.bindView((board) => {
      this.setData({
        beat: false
      })
      this.setData({
        board: board,
        beat: true
      })
    })
    user.bindView((user) => {
      this.setData({
        user: user
      })
    })
  },

  startGame: function() {
    this.reset()
    numberBoard.start()
  },

  numberInput: function (event) {
    this.setData({
      inputValue: event.detail.value 
    })
  },

  verify: function (event) {
    numberBoard.verify(this.data.inputValue)
  },

  reset: function () {
    user.flushUserInfo()
    this.setData({
      inputValue: ''
    })
  }
})
